package ${package.Entity};

<#list table.importPackages as pkg>
import ${pkg};
</#list>
<#list table.fields as field>
<#if field.propertyType=="LocalDateTime">
import java.util.Date;
</#if>
</#list>
<#if swagger2>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
</#if>
<#if entityLombokModel>
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
</#if>
<#if entityTableNeedExportFlag>
import ${table.parentPackage}.common.excel.annotation.ExcelField;
</#if>
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * <p>
 * ${table.comment!}
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if entityLombokModel>
@Data
@NoArgsConstructor
@AllArgsConstructor
    <#if superEntityClass??>
@EqualsAndHashCode(callSuper = true)
    <#else>
@EqualsAndHashCode(callSuper = false)
    </#if>
@Accessors(chain = true)
</#if>
<#if table.convert>
@TableName("${table.name}")
</#if>
<#if swagger2>
@ApiModel(value="${entity}对象", description="${table.comment!}")
</#if>
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass} implements Cloneable {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> implements Cloneable {
<#else>
public class ${entity} implements Serializable,Cloneable {
</#if>

    private static final long serialVersionUID = 1L;
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign keyPropertyName="${field.propertyName}"/>
    </#if>

    <#if field.comment!?length gt 0>
    <#if swagger2>
    @ApiModelProperty(value = "${field.comment}")
    <#else>
    /**
     * ${field.comment}
     */
    </#if>
    </#if>
    <#if field.keyFlag>
    <#-- 主键 -->
        <#if field.keyIdentityFlag>
    @TableId(value = "${field.name}", type = IdType.AUTO)
        <#elseif idType??>
    @TableId(value = "${field.name}", type = IdType.${idType})
        <#elseif field.convert>
    @TableId("${field.name}")
        </#if>
    <#-- 普通字段 -->
    <#elseif field.fill??>
    <#-- -----   存在字段填充设置   ----->
        <#if field.convert>
    @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
        <#else>
    @TableField(fill = FieldFill.${field.fill})
        </#if>
    <#elseif field.convert>
    @TableField("${field.name}")
    </#if>
<#-- 乐观锁注解 -->
    <#if (versionFieldName!"") == field.name>
    @Version
    </#if>
<#-- 逻辑删除注解 -->
    <#if (logicDeleteFieldName!"") == field.name>
    @TableLogic
    </#if>
    <#if entityTableNeedExportFlag>
    @ExcelField(title="${field.comment!}",  align=2 , sort=${field_index+1}, dictType="${field.dictValue!}")
    </#if>
    <#if field.propertyType=="LocalDateTime" || field.propertyType=="Date">
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    </#if>
    <#if field.notNull?? && field.notNull=="1">
    <#if field.maxLength?? && field.maxLength &gt; 0 >
    @Size(min=1, max=${field.maxLength}, message="${field.comment!}长度必须在1~${field.maxLength}个字符")
    <#else>
    @NotBlank(message="${field.comment!}不能为空")
    </#if>
    </#if>
    private <#if field.propertyType=="LocalDateTime">Date<#else>${field.propertyType}</#if> ${field.propertyName};
</#list>
<#------------  END 字段循环遍历  ---------->

<#if !entityLombokModel>
    <#list table.fields as field>
        <#if field.propertyType == "boolean">
            <#assign getprefix="is"/>
        <#else>
            <#assign getprefix="get"/>
        </#if>
    
    @ExcelField(title="${field.comment!}",  align=2 , sort=${field_index+1}, dictType="${field.dictValue!}")
    public <#if field.propertyType=="LocalDateTime">Date<#else>${field.propertyType}</#if> ${getprefix}${field.capitalName}() {
        return ${field.propertyName};
    }

        <#if entityBuilderModel>
    public ${entity} set${field.capitalName}(<#if field.propertyType=="LocalDateTime">Date<#else>${field.propertyType}</#if> ${field.propertyName}) {
        <#else>
    public void set${field.capitalName}(<#if field.propertyType=="LocalDateTime">Date<#else>${field.propertyType}</#if> ${field.propertyName}) {
        </#if>
        this.${field.propertyName} = ${field.propertyName};
        <#if entityBuilderModel>
        return this;
        </#if>
    }
    </#list>
</#if>

<#if entityColumnConstant>
    <#list table.fields as field>
    public static final String ${field.name?upper_case} = "${field.name}";

    </#list>
</#if>
<#if activeRecord>
    @Override
    protected Serializable pkVal() {
    <#if keyPropertyName??>
        return this.${keyPropertyName};
    <#else>
        return super.pkVal();
    </#if>
    }

</#if>

private static ${entity} ${table.entityPath} = new ${entity}();
    
    public static ${entity} getInstance() {
        try {
            return (${entity}) ${table.entityPath}.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return new ${entity}();
    }

}
